package com.ala4.oxcafe.repository.mapper;

import com.ala4.oxcafe.dto.BackendHomeDTO;
import com.ala4.oxcafe.entity.ServiceOrderDetail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/**
 * 服务单明细表Mapper
 *
 * @author PING
 * @version 1.0.0
 * @date 2025/8/15 11:57
 */
public interface ServiceOrderDetailMapper extends BaseMapper<ServiceOrderDetail> {

    @Select("select p.series series,count(t.id) series_count from service_order_detail t left join service_order o on o.id = t.service_id " +
            "LEFT JOIN film_product p on t.product_id = p.id " +
            "where t.create_time >= #{startDate} and t.create_time <= #{endDate} and o.status = 1 and t.del_flag = 0 " +
            "GROUP BY p.series ")
    List<BackendHomeDTO.MonthProductDTO> monthProductCount(@Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);

    @Select("select a.month_str,count(a.id) number from ( " +
            "select DATE_FORMAT(NOW(),'%Y-%m') month_str,t.id from service_order_detail t " +
            "left join service_order o on o.id = t.service_id " +
            "where t.create_time >= #{startDate} and t.create_time <= #{endDate}  and o.status = 1 and t.del_flag = 0 " +
            ") a GROUP BY a.month_str")
    List<BackendHomeDTO.SixMonthProduct> lastSixMonthProductCount(@Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);
}
